package com.xiyili.topspecialty;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.xiyili.topspecialty.data.SpecialtyDatabaseHelper;

public class FineCourseCategoryListFragment extends ListFragment {


	private OnSpecialtyCategoryItemSelectedListener mCallbacks;
	private List<String> items;

	public interface OnSpecialtyCategoryItemSelectedListener{

		public void onSpecialtyCategoryItemSelected(String category);
	}

	/**
	 * Mandatory empty constructor for the fragment manager to instantiate the
	 * fragment (e.g. upon screen orientation changes).
	 */
	public FineCourseCategoryListFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);


		items = SpecialtyDatabaseHelper.getInstance(getActivity())
				.findAllFineCourseCategories();
		setListAdapter(new ArrayAdapter<String>(getActivity(),
				R.layout.simple_fine_course_category_list_item_activated_1,
				R.id.text1,items ));
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		// Activities containing this fragment must implement its callbacks.
		if (!(activity instanceof OnSpecialtyCategoryItemSelectedListener)) {
			throw new IllegalStateException(
					"Activity must implement fragment's callbacks.");
		}

		mCallbacks = (OnSpecialtyCategoryItemSelectedListener) activity;
	}


	@Override
	public void onListItemClick(ListView listView, View view, int position,
			long id) {
		super.onListItemClick(listView, view, position, id);

		// Notify the active callbacks interface (the activity, if the
		// fragment is attached to one) that an item has been selected.
		mCallbacks.onSpecialtyCategoryItemSelected(items.get(position));
	}



}
